#include "gxgfunc.h"
#include "md5.h"

#define BUFFERSIZE 1024

typedef struct task_s
{
    int netFd; //传递文件描述符
    struct task_s *pNext;
} task_t;

typedef struct taskQueue_s
{
    task_t *pFront; //队首
    task_t *pRear;  //队尾
    int size;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} taskQueue_t;

typedef struct threadPool_s
{
    pthread_t *tid; //子线程的数组
    int threadNum;  //子线程数量
    taskQueue_t taskQueue;
    int exitFlag;
} threadPool_t;

/*文件协议*/
typedef struct train_s {
    int length;
    char buf[1000];
} train_t;

/*文件信息结构体*/
typedef struct fileInfo_s
{
    int parentId;
    char fileName[BUFFERSIZE];
    int ownerId;
    char md5[40];
    int fileSize;
    int fileType;
} fileInfo_t;

int taskEnqueue(taskQueue_t *pTaskQueue, int netFd);
int taskDequeue(taskQueue_t *pTaskQueue);
int threadPoolInit(threadPool_t *pThreadPool, int workerNum);
int makeWorker(threadPool_t *pThreadPool);
int tcpInit(int *pSockFd, char *ip, char *port);
int epollAdd(int fd, int epfd);
int epollDel(int fd, int epfd);
int sendn(int sockFd, void* pstart, int len);
int recvn(int sockFd, void* pstart, int len);
int sendFile(const int netFd, const char* fileName);
int recvFile(const int sockFd, fileInfo_t* pFileBuf);
int addFileTologTable(MYSQL* conn, const int log_id, const int user_id , const char* user_name, const char* op_name);
